using MediatR;
using RBAC.ErrorCode;
using SmartHealthcare.Read.Api.DTo;

namespace SmartHealthcare.Read.Api.Application.Command.PatientList
{
    /// <summary>
    /// 获取患者住院登记信息命令
    /// </summary>
    public class GetPatientRegistryCommand : IRequest<APIResult<List<PatientRegistryDto>>>
    {
        /// <summary>
        /// 病人卡号（可空）
        /// </summary>
        public string? MedicalCard { get; set; }

        /// <summary>
        /// 病人姓名（可空）
        /// </summary>
        public string? PatientName { get; set; }

        /// <summary>
        /// 开始时间（可空）
        /// </summary>
        public DateTime? StartTime { get; set; }

        /// <summary>
        /// 结束时间（可空）
        /// </summary>
        public DateTime? EndTime { get; set; }

        /// <summary>
        /// 验证参数
        /// </summary>
        /// <returns></returns>
        public bool IsValid()
        {
            // 至少需要提供一个查询条件
            return !string.IsNullOrWhiteSpace(MedicalCard) 
                || !string.IsNullOrWhiteSpace(PatientName) 
                || StartTime.HasValue 
                || EndTime.HasValue;
        }

        /// <summary>
        /// 检查是否有任何查询参数
        /// </summary>
        /// <returns></returns>
        public bool HasAnyParameter()
        {
            return !string.IsNullOrWhiteSpace(MedicalCard) 
                || !string.IsNullOrWhiteSpace(PatientName) 
                || StartTime.HasValue 
                || EndTime.HasValue;
        }

        /// <summary>
        /// 验证时间范围
        /// </summary>
        /// <returns></returns>
        public bool IsTimeRangeValid()
        {
            if (StartTime.HasValue && EndTime.HasValue)
            {
                return StartTime.Value <= EndTime.Value;
            }
            return true;
        }
    }
} 